<template>
    <div class="app-container">
        <div class="steps1">
            <searchForm :formOptions="formOptions" style="max-height: calc(100vh - 120px);overflow: auto;"
                @onSearch="onSearch" @onReset="onReset" />
            <el-table :data="tableData" style="width: 100%">
                <el-table-column label="姓名" prop="name">
                </el-table-column>
                <el-table-column label="注册号" prop="registerCode">
                </el-table-column>
                <el-table-column label="入学年份" prop="gradeName">
                </el-table-column>
                <el-table-column label="性别" prop="sex">
                    <template slot-scope="{row}">
                        <dict-tag :options="dict.type.sys_user_sex" :value="row.sex"></dict-tag>
                    </template>
                </el-table-column>
                <el-table-column label="所在院部" prop="deptNames">
                </el-table-column>
                <el-table-column label="班级" prop="className">
                </el-table-column>
            </el-table>
        </div>
        <el-row :gutter="20">
            <el-col :span="8" style="margin-top: 15px;">
                <el-form ref="form" :model="dataForm" label-width="120px">
                    <el-col :span="12" v-for="item in evaluateList" :key="item.id">
                        <el-form-item :label="item.quotaDescription" prop="studentNo">
                            <el-input-number v-model="inputNumData[item.quotaId]" :precision="2" :min="0" :step="0.1"
                                :controls="false" :max="item.maxScore"
                                :placeholder="`输入${item.quotaDescription}`"></el-input-number>
                        </el-form-item>
                    </el-col>
                </el-form>
                <div style="text-align: center;">
                    <el-button @click="submit">提交评价</el-button>
                </div>
            </el-col>

            <el-col :span="12">
                <!-- <el-table :data="allocationInfolist">
                    <el-table-column prop="college" show-overflow-tooltip label="院系"> </el-table-column>
                    <el-table-column prop="specialityName" label="专业"> </el-table-column>
                    <el-table-column prop="className" label="班级"> </el-table-column>
                    <el-table-column prop="studentName" label="学生姓名"> </el-table-column>
                    <el-table-column prop="name" label="性别">
                        <template slot-scope="scope">
                            <dict-tag :options="dict.type.sys_user_sex" :value="scope.row.sex"></dict-tag>
                        </template>
                    </el-table-column>
                    <el-table-column prop="houseName" label="楼号"> </el-table-column>
                    <el-table-column prop="roomNo" label="房间号"> </el-table-column>
                    <el-table-column prop="studentNo" label="学号"> </el-table-column>
                    <el-table-column prop="createName" label="分配人"> </el-table-column>
                    <el-table-column prop="createTime" label="分配时间"> </el-table-column>
                    <el-table-column prop="allocationType" label="分配方式"> </el-table-column>
                    <el-table-column label="操作" align="center">
                        <template slot-scope="{row}">
                            <el-button v-if="row.allocationType && row.allocationType.includes('入住')" size="mini"
                                type="text" @click="printAllotDetails(row)">通知单</el-button>
                        </template>
                    </el-table-column>
                </el-table> -->
            </el-col>
        </el-row>
    </div>
</template>
  
<script>
import searchForm from "@/components/Search/searchForm.vue";
import {
    queryStudent,
} from "@/api/information/studentInfor";
import {
    evaluateList,
    postEvaluateInfo 
} from "@/api/assessmentCenter/evaluationIndex";
export default {
    components: {
        searchForm,
    },
    data() {
        return {
            formOptions: [
                {
                    label: "注册号",
                    prop: "registerCode",
                    element: "el-input",
                    placeholder: "请输入注册号",
                },
            ],
            tableData: [],
            studentInfo: {},
            allocationInfolist: [],
            floorData: [],
            roomData: [],
            bedData: [],
            bedParams: {
                roomId: '',
                roomCode: ''
            },
            evaluateList: [],
            dataForm: {
                studentNo: '',
            },
            inputNumData: {},
            selectBedId: null
        };
    },
    dicts: [
        "sys_user_sex",
    ],
    created() {
    },
    async mounted() {
        const { rows } = await evaluateList()
        this.evaluateList = rows;
        rows.forEach(element => {
            this.inputNumData[element.quotaId] = 0
        });

    },
    methods: {
        onSearch(data) {
            if (!data.registerCode) {
                this.$message.warning("请输入注册号");
                return
            }
            this.dataForm = data
            this.getStudentInfo(data)
        },
        onReset(data) {
            this.tableData = []
            this.studentInfo = {}
            this.allocationInfolist = []
        },
        // 获取学生信息
        getStudentInfo(data) {
            queryStudent({
                registerOrSno: data.registerCode
            }).then((res) => {
                if (res.data) {
                    this.studentInfo = res.data
                    this.tableData = [res.data]
                } else {
                    this.$message.warning("未搜索到对应学生");
                }
            })
        },
        // 提交评价
        submit() {
            if(this.tableData.length == 0){
                this.$message("请选择要评价的学生")
                return;
            }
            let evaluateScoreList = [], totalScore = 0;
            for (let k in this.inputNumData) {
                evaluateScoreList.push({
                    realScore: this.inputNumData[k],
                    quotaId: k
                })
                totalScore += this.inputNumData[k]

            }
            debugger
            postEvaluateInfo({
                evaluateScoreList,
                totalScore,
                registerCode:this.dataForm.registerCode
            })
        }
    }
};
</script>
  
<style lang="scss" scoped>
.demo-table-expand {
    font-size: 0;
}

.demo-table-expand label {
    width: 90px;
    // color: #99a9bf;
}

.demo-table-expand {
    .el-form-item {
        margin-right: 0;
        margin-bottom: 0;
        width: 50%;
    }
}

.steps2 {
    margin-top: 12px;
}</style>